<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>添加管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
    <style>
        .x-red {
            color: red;
        }
    </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="x-red">*</span>用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="manageName" lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="x-red">*</span>昵称</label>
        <div class="layui-input-inline">
            <input type="text" name="nickName" lay-verify="required" placeholder="请输入昵称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="x-red">*</span>密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" lay-verify="required" placeholder="请输入登录密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="x-red">*</span>手机号</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> <span class="x-red">*</span>用户角色</label>
        <div class="layui-input-inline">
            <select name="roleId" lay-verify="required">
                <option th:each="r:${roleList}" th:text="${r.roleName}" th:value="${r.getId()}">XX角色</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">说明</label>
        <div class="layui-input-inline">
            <input type="text" name="userDesc" placeholder="请输入说明" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
               value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
               value="确认编辑">
    </div>
</div>

<script th:src="@{/layuiadmin/layui/layui.js}"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$,
            form = layui.form;

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            layer.confirm("是否确认保存", function () {
                layer.load(2);
                $.post("add", data.field, function (res) {
                    layer.closeAll();
                    if (res.code == 0) {
                        layer.msg('保存成功', {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layui.table.reload('LAY-app-content-list'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.alert(res.message, {
                            icon: 2
                        });
                    }

                })
            })


        });
    })
</script>
</body>
</html>
